<?php
namespace Plu\Library\Models\Report\LogRecord;

use Phalcon\Mvc\Model,
    Phalcon\Db\Column;

class LogOperationTypes extends Model {
    public $Id;

    public $Name;

    public $Desc;

    public $ModuleId;

    public $Color;

    const NORMAL_OPERATE  = "#000000";

    const ADD_OPERATE     = "#009900";

    const REMOVE_OPERATE  = "#FF0000";

    const KEY_OPERATE     = "#FF6600";

    const COLOR = array(
        self::NORMAL_OPERATE  => 0,
        self::ADD_OPERATE     => 1,
        self::REMOVE_OPERATE  => 2,
        self::KEY_OPERATE     => 3,
    );

    public function initialize() {
        $this->setWriteConnectionService('db.report');
        $this->setReadConnectionService('db.report.slave');
    }

    public function getSource() {
        return "OperationTypes";
    }

    static public function getItem($name, $moduleId, $color){
        return self::findFirst(array(
            "Name = :name: AND ModuleId = :moduleId: AND Color = :color:",
            "bind" => array(
                "name"     => $name,
                "moduleId" => $moduleId,
                "color"    => $color
            ),
            'bindTypes' => array(
                'Color'	=> Column::BIND_PARAM_INT,
                'moduleId'	=> Column::BIND_PARAM_INT,
            )
        ));
    }
}

?>
